package com.imooc.miaosha.rabbitmq;

import com.imooc.miaosha.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@Slf4j
public class MQSender {

    @Autowired
    AmqpTemplate amqpTemplate;


    public void sendMiaoshaMessage(MiaoshaMessage miaoshaMessage){
        String msg = RedisService.beanToString(miaoshaMessage);
        log.info("miaosha send msg:" + msg);
        //amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE,msg);
        amqpTemplate.convertAndSend(MQConfig.DIRECT_EXCHANGE,"",msg);
    }

/*    public void send(Object message){
        String msg = RedisService.beanToString(message);
        log.info("send message:" + msg);
        amqpTemplate.convertAndSend(MQConfig.QUEUE_NAME1,msg);
    }

    public void topicSend(String message){
        log.info("send message:" + message);
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE,"topicKey1",message);
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE,"topicKey2",message);
    }

    public void fanoutSend(String message){
        log.info("fanout send message:" + message);
        amqpTemplate.convertAndSend(MQConfig.FANOUT_EXCHANGE,null,message);
    }

    public void headersSend(String message){
        log.info("headers send message ：" + message);
        MessageProperties properties = new MessageProperties();
        properties.setHeader("0",0);
        Message msg = new Message(message.getBytes(),properties);

        amqpTemplate.convertAndSend(MQConfig.HEADERS_EXCHANGE,null,msg);
    }*/
}
